草庐IT

SQL CHECK 约束

全部标签

swift - 为什么 layoutIfNeeded() 允许在更新约束时执行动画?

UIView我有两种状态:我在它们之间使用@IBaction为button制作动画:@IBActionfunctapped(sender:UIButton){flag=!flagUIView.animateWithDuration(1.0){ifself.flag{NSLayoutConstraint.activateConstraints([self.myConstraint])}else{NSLayoutConstraint.deactivateConstraints([self.myConstraint])}self.view.layoutIfNeeded()//addition

swift - 具有约束的通用类型的关联值的枚举案例

有没有办法使用泛型和类型约束,将这个enum的前两种情况合并为一种?enumAllowedValueRange{//Associatedvaluerepresents(min,max).'nil'represents//"nolimit"forthatintervalend(+/-infinity)caseIntegerRange(Int?,Int?)//Associatedvaluerepresents(min,max).'nil'represents//"nolimit"forthatintervalend(+/-infinity)caseFloatRange(Float?,Flo

ios - 以编程方式添加一些约束时出现 NSGenericException

简单这是我的代码funcshowMessageView(){letleftConstraint=messageView.leftAnchor.constraintEqualToAnchor(self.view.leftAnchor)letbottomConstraint=messageView.bottomAnchor.constraintGreaterThanOrEqualToAnchor(self.view.bottomAnchor)lethighConstratin=messageView.heightAnchor.constraintEqualToConstant(44.0)l

generics - 您能否扩展具有特定约束的通用类(例如 Array)?

我想扩展Array类,但仅限于符合SequenceType协议(protocol)的元素。我想写的代码/我认为合理的代码是:extensionArray{funcflatten()->[T.Generator.Element]{varresult=[T.Generator.Element]()//***[2]forseq:Tinself{//***[1]foreleminseq{result+=[elem]}}returnresult}}但是,Swift似乎创建了两个版本的T。我假设一个来自正常的Array声明,另一个来自对我的方法的尝试约束。特别是,这意味着第[1]行给出了可爱的错误

ios - iOS9.0 中的动画 anchor 样式约束

使用anchor样式NSLayoutConstraints(如本回答:Swift|Addingconstraintsprogrammatically)如何为subview设置动画?对于那些懒惰的人,这里是代码:overridefuncviewDidLoad(){super.viewDidLoad()letnewView=UIView()newView.backgroundColor=UIColor.redColor()newView.translatesAutoresizingMaskIntoConstraints=falseview.addSubview(newView)lethor

ios - 为一个或另一个扩展具有多个约束的协议(protocol) - Swift

我想使用满足OR(||)约束的默认实现来扩展协议(protocol)。classA{}classB{}protocolSomeProtocol{}///Itwillthrowerrorfor||extensionSomeProtocolwhereSelf:A||Self:B{} 最佳答案 你不能用OR扩展协议(protocol),因为你不能在iflet中这样做,因为编译器会推断出self或var的类型,所以如果它符合2种类型,编译器就不会不知道自己是什么类型。(当您键入self.或任何var时,编译器总是知道编译器类型中的var类型

swift - 设置 `constraint.isActive = false` 是否解除约束?

假设我想删除一个约束,传统上我会这样做:view.removeConstraint(constraint)但是,现在有用于安装/卸载约束的新isActive方法。如果我执行以下操作:constraint.isActive=false它会正确地将其从内存中删除吗? 最佳答案 是的,constraint.isActive=false正在做同样的事情:viewThatOwnsConstraint.removeConstraint(constraint)因此,如果唯一保持约束的是View,那么这将正确地将其从内存中删除。证明如下:letvi

ios - 定位约束没有任何影响

我正在尝试在viewDidLoad函数中对标签进行编码。标checkout现了,但我现在使用的代码不影响定位。我正在尝试对viewDidLoad函数中的所有内容进行编码。你可以看到下面的截图。overridefuncviewDidLoad(){super.viewDidLoad()letbackbutton=UILabel()backbutton.backgroundColor=UIColor.orangebackbutton.translatesAutoresizingMaskIntoConstraints=falsebackbutton.widthAnchor.constraint

ios - 设置 UIImageView 图片影响布局约束

我正在创建一个具有以下约束的简单UIImageView:self.view.addConstraint(imageView.topAnchor.constraint(equalTo:contentLayoutGuide.topAnchor))self.view.addConstraint(imageView.centerXAnchor.constraint(equalTo:contentLayoutGuide.centerXAnchor))self.view.addConstraint(imageView.heightAnchor.constraint(equalTo:contentL

ios - Swift 扩展 - 必须在非专用泛型类型 'Array' 上声明约束扩展

我有一个返回JSON对象数组的API。我已将结构设置为如下所示:typealiasMyModels=[MyModel]structMyModel:Codable{letfield1:Stringletfield2:StringletmySubModel:SubModel?enumCodingKeys:String,CodingKey{casefield1="Field1"casefield2="Field2"casemySubModel="MySubModel"}}structSubModel:Codable{letsubModelField1:StringletsubModelFie